#include "ws2812.h"


WS28XX_DataTypeStruct ws2812Data;



void show()
{
    FL_DMA_ConfigTypeDef ws2812_dma_str;
    ws2812_dma_str.memoryAddress=(uint32_t)(&ws2812Data);
    ws2812_dma_str.transmissionCount=sizeof(ws2812Data);
    FL_DMA_Enable(DMA);
    FL_DMA_StartTransmission(DMA, &ws2812_dma_str, FL_DMA_CHANNEL_0);
    FL_GPTIM_Enable(GPTIM0);
    
}

void setPixeColor_RGB(uint16_t index, uint8_t r, uint8_t g, uint8_t b)
{
    uint8_t j;
    if(index>PIXEL_SIZE)
    {
        return;
    }
    for(j=0;j<8;j++)
    {
        ws2812Data.ColorRealData[24*index+j]    = (g&(0x80>>j))?BIT_1:BIT_0;
        ws2812Data.ColorRealData[24*index+j+8]  = (r&(0x80>>j))?BIT_1:BIT_0;
        ws2812Data.ColorRealData[24*index+j+16] = (b&(0x80>>j))?BIT_1:BIT_0;
    }
}

void setAllColor_RGB(uint8_t r, uint8_t g, uint8_t b)
{
    uint16_t index;
    for(index=0;index<PIXEL_SIZE;index++)
    {
        setPixeColor_RGB(index,r,g,b);
    }
}
